/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kurvykurvy.page;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author HY
 */
public class BookTemplate
{
    BufferedImage pageSpreadMask;
    
    ArrayList<PageLayoutTemplate> leftPageTemplates;
    ArrayList<PageLayoutTemplate> rightPageTemplates;

    public BookTemplate()
    {
        
    }

    public ArrayList<PageLayoutTemplate> getPageTemplates()
    {
        ArrayList<PageLayoutTemplate> templates = new ArrayList();
        templates.addAll( leftPageTemplates );
        templates.addAll( rightPageTemplates );
        System.out.println( "Total templates : " + templates.size() );
        return templates;
    }

    public void setPageTemplates( ArrayList<PageLayoutTemplate> pageTemplates )
    {
        if( pageTemplates != null )
        {
            for( Iterator<PageLayoutTemplate> it = pageTemplates.iterator(); it.hasNext(); )
            {
                addPageTemplate( it.next() );
            }
        }
    }
    
    public void addPageTemplate( PageLayoutTemplate template )
    {
        if( template != null )
        {
            if( template.isLeft() )
            {
                System.out.println( "Adding left template" );
                if( leftPageTemplates == null )
                    leftPageTemplates = new ArrayList<PageLayoutTemplate>();

                leftPageTemplates.add( template );
                System.out.println( "Left templates : " + leftPageTemplates.size() );
            }
            else
            {
                System.out.println( "Adding right template" );
                if( rightPageTemplates == null )
                    rightPageTemplates = new ArrayList<PageLayoutTemplate>();

                rightPageTemplates.add( template );
                System.out.println( "Right templates : " + leftPageTemplates.size() );
            }
        }
    }

    public void removePageTemplate( PageLayoutTemplate template )
    {
        if( template != null )
        {
            if( template.isLeft() && leftPageTemplates != null )
            {
                leftPageTemplates.remove( template );
            }
            else if( rightPageTemplates != null )
            {
                rightPageTemplates.remove( template );
            }
        }
    }

    public PageLayoutTemplate getLeftPageTemplate()
    {
        if( leftPageTemplates != null && !leftPageTemplates.isEmpty() )
        {
            return leftPageTemplates.get(  0 );
        }
        else
            return null;
    }

    public PageLayoutTemplate getRightPageTemplate()
    {
        if( rightPageTemplates != null && !rightPageTemplates.isEmpty() )
        {
            return rightPageTemplates.get(  0 );
        }
        else
            return null;
    }

    public BufferedImage getPageSpreadMask()
    {
        return pageSpreadMask;
    }

    public void setPageSpreadMask( BufferedImage pageSpreadMask )
    {
        this.pageSpreadMask = pageSpreadMask;
    }
}
